package com.wind.salebooking;


import com.google.gson.Gson;
import com.wind.salebooking.model.SaleBookingVO;
import com.wind.salebooking.service.SaleBookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by Administrator on 2016/1/4.
 */
@Controller
@RequestMapping(value = "/sales")
public class SaleBookingController {
    @Autowired
    private SaleBookingService saleBookingService;
    private Gson gson = new Gson();


    @RequestMapping(produces = "text/plain;charset=UTF-8",value = "/getSaleBookingList",method = RequestMethod.POST)
    @ResponseBody()
    public String getSalesBookingList(HttpServletRequest request){
        int salesmanId = Integer.parseInt(request.getParameter("salesmanId"));
        return  gson.toJson(saleBookingService.getSalesList(salesmanId));
    }

    @RequestMapping(produces = "text/plain;charset=UTF-8",value="/getSalesBookingDts",method = RequestMethod.POST)
    @ResponseBody
    public String getSalesBookingDts(HttpServletRequest request){
        String bookingId = request.getParameter("bookingId");
        SaleBookingVO bookingVO = saleBookingService.getSaleBookingDts(bookingId);
        bookingVO.getComposites().addAll(saleBookingService.getComposite(bookingId));
        return gson.toJson(bookingVO);
    }
}
